<?php
$this->breadcrumbs=array(
	'Insurances'=>array('index'),
	$model->id,
);

if (Yii::app()->user->role == "employee"){
$this->menu=array(
	array('label'=>'List Insurance', 'url'=>array('index')),
	array('label'=>'Create Insurance', 'url'=>array('create')),
	array('label'=>'Update Insurance', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Delete Insurance', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage Insurance', 'url'=>array('admin')),
);
}
?>

<!--h1><//?php echo $model->InsuranceType->type_name; ?></h1-->

<?php $this->widget('zii.widgets.CDetailView', array(
	'data'=>$model,
	'attributes'=>array(
		//'id',
		'client.Names',
		'insurance_type_id',
		'insurance_company_id',
		'policynum',
		'policy_dateissued',
		'policy_dateexp',
		'insureditems',
		'termprice',
		'policy_coverage',
		//'attachment',
	),
)); ?>

<?php $cid= Yii::app()->user->getState('uid');?>
<h2>Payments</h2>
<?php
/**
SELECT * 
FROM payment t
LEFT JOIN insurance_has_payment ip ON ip.payment_id=t.id 
LEFT JOIN insurance i ON ip.insurance_id=i.id
LEFT JOIN insurance_type itype ON i.insurance_type_id=itype.id
WHERE i.client_id='{id}' and ip.insurance_id='{insurance_id}'
**/
$cpay=new CDbCriteria;
$cpay->select='*';
$cpay->join = 'LEFT JOIN insurance_has_payment ip ON ip.payment_id=t.id LEFT JOIN insurance i ON ip.insurance_id=i.id LEFT JOIN insurance_type itype ON i.insurance_type_id=itype.id';
$cpay->condition='i.client_id=:cid and ip.insurance_id=:insid'; // AND itype.id=:type
$cpay->params = array(':cid'=>$cid, ':insid'=>$model->id); //, 'type'=>$type
$cpay->order = 'date DESC';
//$cpay->limit = '1';
$payment=Payment::model()->findAll($cpay);

if (count($payment) !== 0){?>
<table>
	<thead> <tr> <th>Payroll Date</th> <th>Payment Amount</th> </tr> </thead>

<?php foreach ($payment as $row) { ?>
	<tr>
		<td><?php echo CHtml::encode(Yii::app()->dateFormatter->formatDateTime($row->date, 'long', false)); ?></td>
		<td><?php echo $row->amount; ?></td>
	</tr>
<?php }} else {	echo "<b><i>No Records Found.</i></b>";	} ?>
	<!--tr>
		<td><b>Total</b></td>
		<td></td>
	</tr-->
</table>